#include "PrecompiledHeaders.h"
#include "GameSession.h"

GameSession::GameSession()
{
	gameScore = INIT_SCORE;
	gameLives = INIT_LIVES;
	highScoreAdded = false;
	replay = false;
}

GameSession::GameSession(const GameSession& o)
{
    levelScore = o.levelScore;
    levelLives = o.levelLives;
    levelBonus = o.levelBonus;
    gameLives = o.gameLives;
    gameScore = o.gameScore;
    levelTimeLeft = o.levelTimeLeft;
    currentState = o.currentState;
    highScoreAdded = o.highScoreAdded;
}

void GameSession::beginStoryModeLevel()
{
    if(replay)
        return;
    currentState = ssPLAYING_SM;
    levelScore = 0;
    levelLives = 0;
    levelTimeLeft = 0;
    levelBonus = 0;
}

void GameSession::endStoryModeLevel(bool failedGame)
{
    if(replay)
        return;
    if(levelLives > 0)
        levelBonus += levelLives * LIFE_BONUS;
    levelBonus += levelTimeLeft * TIME_BONUS;
    
    // If failed game, dont add on score for last level
    if(!failedGame) {
	    gameScore += (levelScore + levelBonus);
	}
}

void GameSession::beginQuickPlay()
{
    if(replay) {
        return;
    }
    currentState = ssPLAYING_QP;
    levelScore = 0;
    levelLives = 0;
    levelTimeLeft = 0;
    levelBonus = 0;
    gameScore = 0;
	gameLives = 0;
}

void GameSession::endQuickPlay()
{
    if(replay)
        return;
    if(levelLives > 0)
        levelBonus += levelLives * LIFE_BONUS;
    levelBonus += levelTimeLeft * TIME_BONUS;
	gameScore += (levelScore + levelBonus);
}

void GameSession::beginBonusRun()
{
    if(replay) {
        return;
    }
    currentState = ssPLAYING_BONUS;
    levelScore = 0;
    levelLives = 0;
    levelTimeLeft = 0;
    levelBonus = 0;
}

void GameSession::endBonusRun()
{
    if(replay)
        return;
    if(levelLives > 0)
        levelBonus += levelLives * LIFE_BONUS;
    levelBonus += levelTimeLeft * TIME_BONUS;
	gameScore += (levelScore + levelBonus);
}

int GameSession::getNumLives(void)
{
    //if(currentState == ssPLAYING_BONUS)
    //    return 0;
    return gameLives;
}

void GameSession::addScore(int deltaScore)
{
    if(replay)
        return;
    levelScore += deltaScore;
}

void GameSession::setTimeLeft(float time)
{
    if(replay)
        return;
    levelTimeLeft = time;
}

void GameSession::addLife(void)
{
    if(replay)
        return;
    levelLives++;
    gameLives++;
}

bool GameSession::removeLife(void)
{
    if(replay)
        return true;
    if(currentState == ssPLAYING_QP || currentState == ssPLAYING_BONUS)
        return false;
	levelLives--;
	gameLives--;
	return gameLives >= 0;
}

void GameSession::resetLevelScore()
{
    if(replay)
        return;
    levelScore = 0;
    levelTimeLeft = 0;
    levelBonus = 0;
}

void GameSession::print()
{
    printf("Game Session Values:\n");
    printf("\tLevel Score: %i\n", levelScore);
    printf("\tLevel Bonus: %i\n", levelBonus);
    printf("\tGame Lives:  %i\n", gameLives);
    printf("\tGame Score:  %i\n", gameScore);
}
